<?php
defined('SYSPATH') OR die('No direct access allowed.');
/**
 * detail.php
 * @author ranuandra
 *
 * 20 Sep 2011 23:05:59
 *
 * 
 */
?>
Ext.ns('App', 'App.detailreport');
/**
 * App.user.Grid
 * A typical EditorGridPanel extension.
 */
App.detailreport.Grid = Ext.extend(Ext.grid.GridPanel, {
    //renderTo: 'user-grid',
    iconCls: 'silk-grid',
    frame: true,
    //title: 'Users',
    height: 500,

    initComponent : function() {

        // typical viewConfig
        this.viewConfig = {
            forceFit: true
        };

        // Typical Store collecting the Proxy, Reader and Writer together.
        this.store = new Ext.data.JsonStore({
            id: 'detailreport',
            url: '<?php echo URL::base()?>report/detail',
            remoteSort: false,
	        sortInfo: {
	            field: 'date',
	            direction: 'ASC'
	        },
			storeId: 'myStore',
			        
			        // reader configs
			        idProperty: 'id',
			        root: 'detailreport',
			        totalProperty: 'total',
			        fields: [{
			            name: 'date'
			        }, {
			            name: 'code'
			        }, {
			            name: 'material_name',
			        }, {
			            name: 'transaction',
			        },{
			            name: 'qty',
			            type: 'float'
			        }, {
			            name: 'no_order'
			        }, {
			            name: 'origin'
			        }, {
			            name: 'truck_number'
			        }, {
			            name: 'location'
			        }]
        });


        // Let's pretend we rendered our grid-columns with meta-data from our ORM framework.
        this.Columns =  [
		    {header: "Date", width: 40, sortable: true, dataIndex: 'date'},
		    {header: "Code", width: 100, sortable: true, dataIndex: 'code'},
		    {header: "Name", width: 100, sortable: true, dataIndex: 'material_name'},
		    {header: "Transaction", width: 100, sortable: true, dataIndex: 'transaction'},
		    {header: "Qty", width: 100, sortable: true, dataIndex: 'qty'},
		    {header: "No Order", width: 100, sortable: true, dataIndex: 'no_order'},
		    {header: "Origin", width: 100, sortable: true, dataIndex: 'origin'},
		    {header: "No Cont", width: 100, sortable: true, dataIndex: 'truck_number'},
		    {header: "Location", width: 100, sortable: true, dataIndex: 'location'}
		];
        // relay the Store's CRUD events into this grid so these events can be conveniently listened-to in our application-code.
        //this.relayEvents(this.store, ['destroy', 'save', 'update']);
        this.store.load();
        Ext.apply(this, {
    		store: this.store,
    		columns: this.Columns,
    		border:false
    	});
        // build toolbars and buttons.
        //this.tbar = this.buildTopToolbar();
        //this.buttons = this.buildUI();
        //this.bbar = this.buildBottomToolbar();

        // super
        App.detailreport.Grid.superclass.initComponent.call(this);
    },

    /**
     * buildTopToolbar
     */
    buildTopToolbar : function() {
        return [{
            text: 'Add',
            iconCls: 'silk-add',
            handler: this.onAdd,
            scope: this
        }, '-', {
            text: 'Delete',
            iconCls: 'silk-delete',
            handler: this.onDelete,
            scope: this
        }, '-'];
    },

    buildUI : function() {
        return [{
            text: 'Save',
            iconCls: 'icon-save',
            handler: this.onSave,
            scope: this
        }];
    },

    /**
     * onSave
     */
    onSave : function(btn, ev) {
        this.store.save();
    },

    /**
     * onAdd
     */
    onAdd : function(btn, ev) {
        var u = new this.store.recordType({
            first : '',
            last: '',
            email : ''
        });
        this.stopEditing();
        this.store.insert(0, u);
        this.startEditing(0, 1);
    },

    /**
     * onDelete
     */
    onDelete : function(btn, ev) {
        var index = this.getSelectionModel().getSelectedCell();
        if (!index) {
            return false;
        }
        var rec = this.store.getAt(index[0]);
        this.store.remove(rec);
    }
});